package com.liang.frpdemo;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by Administrator on 2015/6/16.
 */
public class NewApiWrapper {
    Api api;

    public NewApiWrapper(){
        api = new DefaultApi();
    }

    public Observable<LocationBean> getLocation(final String address){
        return Observable.create(new Observable.OnSubscribe<LocationBean>() {
            @Override
            public void call(final Subscriber<? super LocationBean> subscriber) {
                api.getLocation(address, new Api.LocationCallBack() {

                    @Override
                    public void onLocationReceived(LocationBean bean) {
                        subscriber.onNext(bean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        subscriber.onError(e);
                    }
                });
            }
        });
    }

    public Observable<Void> submitLocation(final LocationBean bean){
        return Observable.create(new Observable.OnSubscribe<Void>() {
            @Override
            public void call(final Subscriber<? super Void> subscriber) {
                api.submitLocation(bean, new Api.SubmitCallBack() {

                    @Override
                    public void onSubmitReceived() {
                        subscriber.onNext(null);
                    }

                    @Override
                    public void onError(Throwable e) {
                        subscriber.onError(e);
                    }
                });
            }
        });
    }
}
